package com.heima.controller;


import com.heima.pojo.dto.VmType;
import com.heima.pojo.dto.VmTypeQuery;
import com.heima.pojo.vo.PageVo;
import com.heima.service.IVmTypeService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 售货机类型表 前端控制器
 * </p>
 *
 * @author 存折
 * @since 2024-10-20
 */
@RestController
@RequestMapping("/api/vm-service/vmType")
@Slf4j
public class VmTypeController {
    @Autowired
    private IVmTypeService iVmTypeService;

    @GetMapping("/search")
    public PageVo<VmType> query(VmTypeQuery vmTypeQuery){
        return iVmTypeService.query(vmTypeQuery);
    }

    @PostMapping
    public Boolean add(@RequestBody VmType vmType){
        log.info("接收到的参数为:{}",vmType);
        iVmTypeService.save(vmType);
        return true;
    }
    @PutMapping("{typeId}")
    public Boolean update(@PathVariable Integer typeId,@RequestBody VmType vmType){
        log.info("接收到的参数为:{},{}",typeId,vmType);
        vmType.setTypeId(typeId);
        iVmTypeService.updateById(vmType);
        return true;
    }
    @DeleteMapping("/{typeId}")
    public Boolean delete(@PathVariable Integer typeId){
        iVmTypeService.removeById(typeId);
        return true;
    }
}
